package com.ds.api.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ds.api.dao.UserKeyMapper;
import com.ds.api.model.UserKey;
import com.google.gson.Gson;

@RestController
@RequestMapping("/login")
public class UserKeyController extends BaseController {
    
    private static final Logger log = LoggerFactory
            .getLogger(BaseController.class);
    
    @Autowired
    private UserKeyMapper keyMapper;
    /**
     * 忘记密码
     */
    @RequestMapping(value = "/out")
    public  void forget(@RequestParam Map<String,String> param,
            HttpServletRequest request, HttpServletResponse response) {
        String resultStr="0";
        Map<String,Object> result=new HashMap<String,Object>();
        String key=param.get("key");
        UserKey user=new UserKey();
        user.setUidKey(key);
        List<UserKey> userkeys=keyMapper.query(user);
        if(userkeys.size()>0){
            user.setId(userkeys.get(0).getId());
            user.setIsActive("1");
            user.setUpdateTime(new Date());
            keyMapper.updateByPrimaryKeySelective(user);
        }
      
        result.put("result",resultStr);
        Gson gson = new Gson();
        try {
            response.setCharacterEncoding("utf-8");
            response.getWriter().println(gson.toJson(result));
        } catch (Exception e) {
            log.info("程序出错："+e);
        }

    }
}
